<template>
	<s-layout title="我的消息" :bgStyle="{ color: '#303030' }">
		<view class="list-box">
			<view v-for="item in 8" class="list-item">
				<view class="list-item-t">
					<view class="list-item-t-1">公告：关于规范平台用户言论的公告</view>
					<view class="list-item-t-2">2024-01-02 10:50:00</view>
				</view>
				<view class="list-item-b">
					<text>查看详情</text>
					<image src="@/static/img/public-icon-1.png" mode=""></image>
				</view>
			</view>
		</view>
	</s-layout>
</template>

<script setup>
	import sheep from '@/sheep';
	import {
		reactive
	} from 'vue';
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
	import _ from 'lodash';

	const sys_navBar = sheep.$platform.navbar;
	const pagination = {
		data: [],
		current_page: 1,
		total: 1,
		last_page: 1,
	};
	const state = reactive({
		pagination: {
			data: [],
			current_page: 1,
			total: 1,
			last_page: 1,
		},
		loadStatus: '',
		editMode: false,
		selectedCollectList: [],
		selectAll: false,
	});

	async function getData(page = 1, list_rows = 10) {
		state.loadStatus = 'loading';
		let res = await sheep.$api.user.goodsLog.list({
			type: 'views',
			list_rows,
			page,
		});
		if (res.code === 1) {
			let orderList = _.concat(state.pagination.data, res.data.data);
			state.pagination = {
				...res.data,
				data: orderList,
			};
			if (state.pagination.current_page < state.pagination.last_page) {
				state.loadStatus = 'more';
			} else {
				state.loadStatus = 'noMore';
			}
		}
	}
	// 格式化价格
	function formatPrice(e) {
		return e.length === 1 ? e[0] : e.join('~');
	}

	// 单选选中
	const onSelect = (id) => {
		if (!state.selectedCollectList.includes(id)) {
			state.selectedCollectList.push(id);
		} else {
			state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1);
		}
		state.selectAll = state.selectedCollectList.length === state.pagination.data.length;
	};
	// 全选
	const onSelectAll = () => {
		state.selectAll = !state.selectAll;
		if (!state.selectAll) {
			state.selectedCollectList = [];
		} else {
			state.pagination.data.forEach((item) => {
				if (state.selectedCollectList.includes(item.goods_id)) {
					state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1);
				}
				state.selectedCollectList.push(item.goods_id);
			});
		}
	};
	async function onCancel() {
		if (state.selectedCollectList) {
			state.selectedCollectList = state.selectedCollectList.toString();
			const {
				code
			} = await sheep.$api.user.view.delete({
				goods_id: state.selectedCollectList,
			});
			if (code === 1) {
				state.editMode = false;
				state.selectedCollectList = [];
				state.selectAll = false;
				state.pagination = pagination;
				getData();
			}
		}
	}
	// 加载更多
	function loadmore() {
		if (state.loadStatus !== 'noMore') {
			getData(state.pagination.current_page + 1);
		}
	}
	onReachBottom(() => {});
	onLoad(() => {});
</script>

<style lang="scss" scoped>
	.list-box {
		.list-item{
			background: #1E1E1E;
			border-radius: 20rpx;
			margin: 30rpx;
			.list-item-t{
				padding: 30rpx;
				.list-item-t-1{

					font-weight: 400;
					font-size: 34rpx;
					color: #E4E4E4;
				}
				.list-item-t-2{
					margin-top: 30rpx;

					font-weight: 400;
					font-size: 24rpx;
					color: #767676;
				}
			}
			.list-item-b{
				padding: 30rpx;
				border-top: 1px solid #353535;

				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: space-between;
				image{
					width: 13rpx;
					height: 23rpx;
				}
			}
		}
	}
</style>
